package com.pbdevj.jdbc.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class JdbcUtil
{
	public static Connection getConn()
	{
		Connection conn = null;

		// 1.加载驱动类
		try
		{
			Class.forName("com.mysql.jdbc.Driver");

			// 2.获取连接
			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/pbdevj1030", "root", "root");
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}

		return conn;
	}

	public static void closeConn(ResultSet rs, PreparedStatement ps, Connection conn)
	{
		if (rs != null)
		{
			try
			{
				rs.close();
			}
			catch (SQLException e)
			{
				e.printStackTrace();
			}
		}

		if (ps != null)
		{
			try
			{
				ps.close();
			}
			catch (SQLException e)
			{
				e.printStackTrace();
			}
		}

		if (conn != null)
		{
			try
			{
				conn.close();
			}
			catch (SQLException e)
			{
				e.printStackTrace();
			}
		}
	}
}
